package org.example;

import java.sql.*;

public class JDBCConn {
    private JDBCConn() {
    }

    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public static final String url = "jdbc:mysql://localhost:3306/myschool?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
    public static final String user = "root";
    public static final String pass = "123456";

    public  static Connection getConnection(){
        try {
            return DriverManager.getConnection(url,user,pass);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    public static void close(ResultSet rs, Statement stmt,Connection con){
        close(rs);
        close(stmt);
        close(con);
    }
    public static void close(ResultSet rs){
        if (rs == null){
            return;
        }
        try {
            rs.close();
        } catch (Exception e) {
           // throw new RuntimeException(e);
        }
    }
    public static void close(Statement stmt){
        if (stmt == null){
            return;
        }
        try {
            stmt.close();
        } catch (SQLException e) {
            //throw new RuntimeException(e);
        }
    }
    public static void close(Connection con){
        if (con == null){
            return;
        }
        try {
            con.close();
        } catch (SQLException e) {
            //throw new RuntimeException(e);
        }
    }


}
